const path = require('path');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin")
module.exports = {
    //入口配置
    entry: path.resolve(__dirname, "../src/index.js"),

    //出口配置
    output: {
        path: path.resolve(__dirname, "../build"),
        filename: "./js/main.js",
        publicPath : "/"
    },
    //loader配置
    module: {
        // rules: [{
        //     test: /\.html$/i,
        //     use :["html-loader"]
        // }],
        rules: [
            //......
            {
                test: /\.ejs$/,
                loader: 'ejs-loader',
                options: {
                    variable: 'data', // 可以在模块当中使用data进行数据处理
                }
            },{
                test: /\.css$/i,
                use: [
                  //use中loader加载是有顺序的，先下后上，注意有的loader需要按照顺序书写
                  "style-loader",
                  'css-loader'
                ]
              }],
    },

    //插件的配置
    plugins: [
        //生成html文件 并设置对应的参照模板
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, "../public/index.html")
        }), new CopyWebpackPlugin({
            patterns: [{
                from: path.resolve(__dirname, "../public"),
                to: "public",
                globOptions: {
                    ignore: ["**/index.html"]
                }
            }],
        })
    ],
    resolve: {
        //配置路径别名
        alias: {
          $v: path.resolve(__dirname, "../src/views"),
          $r: path.resolve(__dirname, "../src/routes"),
          $a: path.resolve(__dirname, "../src/api"),
        },
    
        //配置引入文件时 省略后缀,自动添加后缀的顺序
        extensions: [".js", ".json", ".ejs"]
      },
    

    //模式
    mode: "production"
}